package com.xjy.web.controller.system;

import java.util.List;
import java.util.Arrays;

import com.xjy.system.domain.SysStaff;
import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.xjy.common.annotation.RepeatSubmit;
import com.xjy.common.annotation.Log;
import com.xjy.common.core.controller.BaseController;
import com.xjy.common.core.domain.AjaxResult;
import com.xjy.common.enums.BusinessType;
import com.xjy.system.domain.vo.SysStaffVo;
import com.xjy.system.domain.bo.SysStaffQueryBo;
import com.xjy.system.domain.bo.SysStaffAddBo;
import com.xjy.system.domain.bo.SysStaffEditBo;
import com.xjy.system.service.ISysStaffService;
import com.xjy.common.utils.poi.ExcelUtil;
import com.xjy.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 员工管理Controller
 *
 * @author xjy
 * @date 2022-02-17
 */
@Api(value = "员工管理控制器", tags = {"员工管理管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/system/staff")
public class SysStaffController extends BaseController {

    private final ISysStaffService iSysStaffService;

    /**
     * 查询员工管理列表
     */
    @ApiOperation("查询员工管理列表")
    @PreAuthorize("@ss.hasPermi('system:staff:list')")
    @GetMapping("/list")
    public TableDataInfo<SysStaffVo> list(@Validated SysStaffQueryBo bo) {
        return iSysStaffService.queryPageList(bo);
    }

    /**
     * 导出员工管理列表
     */
    @ApiOperation("导出员工管理列表")
    @PreAuthorize("@ss.hasPermi('system:staff:export')")
    @Log(title = "员工管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<SysStaffVo> export(@Validated SysStaffQueryBo bo) {
        List<SysStaffVo> list = iSysStaffService.queryList(bo);
        ExcelUtil<SysStaffVo> util = new ExcelUtil<SysStaffVo>(SysStaffVo.class);
        return util.exportExcel(list, "员工管理");
    }

    /**
     * 获取员工管理详细信息
     */
    @ApiOperation("获取员工管理详细信息")
    @PreAuthorize("@ss.hasPermi('system:staff:query')")
    @GetMapping("/{staffId}")
    public AjaxResult<SysStaffVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("staffId") Long staffId) {
        return AjaxResult.success(iSysStaffService.queryById(staffId));
    }

	/**
	 * 获取员工管理详细信息
	 */
	@ApiOperation("获取员工管理详细信息")
//	@PreAuthorize("@ss.hasPermi('system:staff:query')")
	@GetMapping("/deptId")
	public List<SysStaff> getInfodept(Long deptId) {
		return iSysStaffService.querydeptById(deptId);
	}


	/**
     * 新增员工管理
     */
    @ApiOperation("新增员工管理")
    @PreAuthorize("@ss.hasPermi('system:staff:add')")
    @Log(title = "员工管理", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody SysStaffAddBo bo) {
        return toAjax(iSysStaffService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改员工管理
     */
    @ApiOperation("修改员工管理")
    @PreAuthorize("@ss.hasPermi('system:staff:edit')")
    @Log(title = "员工管理", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated @RequestBody SysStaffEditBo bo) {
        return toAjax(iSysStaffService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除员工管理
     */
    @ApiOperation("删除员工管理")
    @PreAuthorize("@ss.hasPermi('system:staff:remove')")
    @Log(title = "员工管理" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{staffIds}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] staffIds) {
        return toAjax(iSysStaffService.deleteWithValidByIds(Arrays.asList(staffIds), true) ? 1 : 0);
    }


}
